/*
 * To change this template, choose Tools | Templates
 * AND open the template in the editor.
 */

package modelos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author usuario
 */
public class ModeloCategoria extends ModeloDB{
    

    public ModeloCategoria() {
        super();
    }

    public boolean registar(){
        abrirConexion();
        boolean sw= false;
        String tira="INSERT INTO Categoria (codigo,descripcion,estatus ) VALUES("+getCodigo()+",'"+getDescripcion()+"','"+getEstatus()+"')";
        try {
            Statement stam = conexion.createStatement();
            stam.execute(tira);
            sw= true;
        } catch (SQLException ex) {
            sw= false;
        }
        cerrarConexion();
        return sw;
    }

    public LinkedList<ModeloCategoria> consultarGeneral(){
        LinkedList<ModeloCategoria> v = new LinkedList<ModeloCategoria>();
        String tira="SELECT * FROM Categoria WHERE estatus='A'";
        abrirConexion();
        try {
            Statement stam = conexion.createStatement();
             ResultSet rs =        stam.executeQuery(tira);
             while (rs.next()){
                 ModeloCategoria  i = new ModeloCategoria();
                i.setDescripcion(rs.getString("descripcion"));
                i.setCodigo(rs.getInt("codigo"));
                i.setEstatus(rs.getString("estatus"));
                v.add(i);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ModeloCategoria.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
  }

  




}
